package com.example.administrator.mytest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.widget.TextView;

import com.google.gson.Gson;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

public class MainActivity extends AppCompatActivity {
    private TextView textView,textView2;
    private RecyclerView mRecyclerView;
    private RecAdapter recAdapter;
    private Data data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mRecyclerView = (RecyclerView) findViewById(R.id.recycle);
        
        getview();
    }
    
    private void getview() {
        RequestParams params  = new RequestParams("http://jiudu.jbserver.me/apicore/index/order_info/user_id/8");
        x.http().get(params, new Callback.CommonCallback<String>() {     
            @Override
            public void onSuccess(String result) {

                data =new Gson().fromJson(result,Data.class);
//                mRecyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
//                mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(90, OrientationHelper.VERTICAL));//这里用线性宫格显示 类似于瀑布流
//                    mRecyclerView.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));//这里用线性宫格显示 类似于grid view
                 //这里用线性显示 类似于listview
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                mRecyclerView.setLayoutManager(linearLayoutManager);
                mRecyclerView.setAdapter(new RecAdapter(MainActivity.this,data.getData()));
                }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        return super.onCreateOptionsMenu(menu);
    }
    
    
}
